export default {
    //声明组件属性
    props: {
        checked: {
            default: false
        },
        goodsId:{
            default:0
        },
        goodsName: {
            default: ''
        },
        goodsImage: {
            default: ''
        },
        price: {
            default: 0
        },
        goodsNum: {
            default: 1
        }
    },
    data: {
        num:0,
        selectedImage :'/common/icon/未选中.png'
    },
    onInit() {
        this.num = this.goodsNum;
        this.toggleIcon()
        this.$watch('checked', 'toggleIcon');
    },
    dec(){
        if (this.num > 1) {
            this.num--;
            this.$emit('changeNum', {
                num:this.num,
                id:this.goodsId
            });
        }else {
            this.$element('dialog').show()
        }
    },

    inc(){
        this.num++;
        this.$emit('changeNum', {
            num:this.num,
            id:this.goodsId
        });
    },
    toggle(){
        this.checked = !this.checked
        this.toggleIcon()
        let r = this.checked;
        this.$emit('changeChecked', {
            result:r,
            id:this.goodsId
        });
    },
    toggleIcon(){
        if (this.checked) {
            this.selectedImage = '/common/icon/选中.png'
        }else {
            this.selectedImage = '/common/icon/未选中.png'
        }
    },
    yes(){
        this.$element('dialog').close()
        this.$emit('changeNum', {
            num:0,
            id:this.goodsId
        });
    },
    no(){
        this.$element('dialog').close()
    }

}
